<HTML><HEAD><TITLE>delete(?Element, ?List1, ?List2)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(lists)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>delete(?Element, ?List1, ?List2)</H1>
Succeeds if List2 is List1 less an occurence of Element in List1.


<DL>
<DT><EM>?Element</EM></DT>
<DD>Prolog term.
</DD>
<DT><EM>?List1</EM></DT>
<DD>List or variable.
</DD>
<DT><EM>?List2</EM></DT>
<DD>List or variable.
</DD>
</DL>
<H2>Description</H2>
   Unifies the list List2 with the list List1 less an occurence of Element.
   Any alternative solutions are provided on backtracking.
<P>
   This predicate can be used to select an element from a list, delete an
   element or insert it.
<P>
   The definition of this Prolog library predicate is:
<PRE>
    delete(A, [A|B], B).
    delete(A, [B, C|D], [B|E]) :-
	    delete(A, [C|D], E).
</PRE>
   This predicate does not perform any type testing functions.
   
<H3>Modes and Determinism</H3><UL>
<LI>delete(+, +, -) is nondet
<LI>delete(-, +, -) is nondet
<LI>delete(-, -, -) is multi
</UL>
<H3>Fail Conditions</H3>
   Fails if List2 does not unify with List1 less an occurence of Element.


<H3>Resatisfiable</H3>
   Yes.
<H2>Examples</H2>
<PRE>
Success:
   [eclipse]: delete(X,[1,M,X],L), writeln((M,X,L)), fail.
   _g66 , 1 , [_g66, 1]
   _g66 , _g66 , [1, _g66]
   _g66 , _g72 , [1, _g66]
   no (more) solution.

   [eclipse]: delete(3,[1,3,5,3],L).
   L = [1, 5, 3]    More? (;)
   L = [1, 3, 5]
   yes.

   [eclipse]: delete(X,L,[a,b]), writeln((X,L)), fail.
   _g66 , [_g66, a, b]
   _g66 , [a, _g66, b]
   _g66 , [a, b, _g66]
   no (more) solution.

   delete(X,[1,2],L).   (gives X=1 L=[2]; X=2 L=[1]).
Fail:
   delete(1,[1,2,1,3],[2,3]).



</PRE>
<H2>See Also</H2>
<A HREF="../../lib/lists/subtract-3.html">subtract / 3</A>, <A HREF="../../lib/lists/member-2.html">member / 2</A>
</BODY></HTML>
